#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "unistd.h"
#include "sys/types.h"
#include "fcntl.h"

#define KEY0VALUE  0xF0
#define INVAVALUE  0x00


int main(int argc, char *argv[])
{

    int fd,ret_val;
    unsigned char *filename;
    unsigned char keyvalue;
    if (argc != 3)
    {
        printf("Usage: ERROR\r\n");
        return -1;
    }
    
    filename = argv[1];

    fd = open(filename,O_RDWR);
    if (fd < 0)
    {
        printf("file open failed\r\n");
        return -1;
    }

    while (1)
    {
        ret_val = read(fd,&keyvalue,sizeof(keyvalue));
        if (ret_val < 0)
        {
            //数据错误/无效
        }
        else
        {
            if(keyvalue)
            {
                printf("KEY0 Press,value = %#x\r\n",keyvalue);
            }
        }
        
    }
    
    
    ret_val = close(fd);
    if (ret_val < 0)
    {
        printf("LED close failed\r\n");
        return -1;
    }
    
    return 0;
}